
#include <stdio.h>
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#define L 78
#define TIME 3
#define ACCOUNT "123456"
#define PASSWORD "123456"
#define ALL_SIZE 100
#define EMPLOYEE_LEN sizeof(struct employee)
#define COMMUNICATION_LEN sizeof(struct communication)
#define PLATE_NUMBER "1.0.0beta"						 //程序版号
#define CREAT_TIME "2020/12/20"							 //开发时间
#define GITEE "https://gitee.com/huixh/ManagementSystem" //码云地址
#define BLOG "blog.huixh.cn"
struct employee
{
	int num;		   //工号
	char position[20]; //职位
	char name[20];	   //姓名
	char sex[2];	   //性别
	int age;		   //年龄
	char cult[10];	   //文化程度
	int salary;		   //工资
	char state[8];	   //身体状况F
} em[ALL_SIZE];

struct communication //职工通讯录
{
	char name[8];
	char officetel[13];
	char hometel[13];
	char handtel[13];
	char address[13];
} empc[ALL_SIZE];

int flag = 1;

void login();				 //登陆模块
void toxy(int x, int y);	 //定义输出坐标
void menu();				 //菜单
void color(short x);		 //改变背景颜色
void failure();				 //登陆失败
void getBuf(int len);		 //自定义接取缓冲
void list(int flag);		 //主列表
void managementSystem();	 //管理系统模块
void communicateSystem();	 //管理系统模块
void input();				 //输入信息
void over();				 //系统结束
void display();				 //显示职工信息
void show();				 //管理系统模块显示列表
void MySelect(int x, int y); //选项
void HideCursor();			 //隐藏光标
void change();				 //修改
void add();					 //追加
void del();					 //删除
void count();				 //统计
void inputcommunicate();	 //通讯录增加
void updatecommunicate();	 //通讯录修改
void deletecommunicate();	 //通讯录删除
void showcommunicate();		 //通讯录查看
void loginshow();			 //展示登录界面
void showcommunicatelist();	 //展示通讯录界面列表
void selctNum();

void HideCursor() //隐藏光标
{
	CONSOLE_CURSOR_INFO cursor_info = {1, 0};
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}

int main()
{
	//showcommunicateselect();
	srand((unsigned)time(NULL));
	login();
	HideCursor();
	menu();
	//deletecommunicate();
	//managementSystem();
	//inputcommunicate();
	//showcommunicate();
	return 0;
}
void login()
{
	system("title 职工管理系统");		   //标题
	system("mode con cols=120 lines=30 "); //输出控制台大小
	char account[20], password[20];
	int index = 3;
login:
	system("cls");

	loginshow();
	toxy(55, 12);
	scanf("%s", &account);
	toxy(55, 15);
	scanf("%s", &password);
	if ((strcmp(account, ACCOUNT)) == 0 && (strcmp(password, PASSWORD)) == 0)
	{
		return;
	}
	else
	{
		printf("\r");
		toxy(30, 5);
		if (index-- == 1)
		{
			failure();
		}
		toxy(42, 22);
		printf("密码错误，您还有%d次机会，请重试！", index);
		getBuf(2);
		goto login;
	}
}
void toxy(int x, int y)
{
	COORD pos = {x, y};
	HANDLE Out = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(Out, pos);
}
void failure()
{
	toxy(42, 22);
	printf("3次机会已耗尽,请查证后再试。\n");
	exit(0);
}

void getBuf(int len)
{
	int index;
	for (index = 0; index < len; index++)
	{
		getchar();
	}
}
void menu()
{
	list(0);
	do
	{
		printf("\r");
		toxy(50, 25);
		printf("输入您的选项：");
		int buf;
		scanf("%d", &buf);
		switch (buf)
		{
		case 1:
			//通讯录
			communicateSystem();
			break;
		case 2:
			selctNum();
			break;
		case 3:
			managementSystem();
			break;
		case 4:
			over();
			break;
		default:
			printf("\r");
			toxy(50, 25);
			printf("您的输入有误！");
			getBuf(2);
		}
	} while (1);
}
void list(int flag)
{
	if (flag == 0)
		system("cls");
	int i;
	toxy(20, 3);
	for (i = 0; i < 80; i++)
	{
		if (i % 2 == 0)
		{
			color(i % 15);
			Sleep(TIME);
			printf("*");
		}
		else
		{
			printf(" ");
		}
	}
	toxy(L, 7);
	printf("1.  通讯簿   ");
	toxy(35, 7);
	printf("开发团队");
	toxy(25, 9);
	printf("张金辉");
	toxy(36, 9);
	printf("李浩然");
	toxy(25, 11);
	printf("李佳鑫");
	toxy(36, 11);
	printf("谭 斌");
	toxy(47, 9);
	printf("柏友成");
	toxy(47, 11);
	printf("冯 旭");
	toxy(25, 15);
	printf("程序版号: %s", PLATE_NUMBER);
	toxy(25, 17);
	printf("开发时间: %s", CREAT_TIME);
	toxy(25, 19);
	printf("博客地址: %s", BLOG);
	toxy(25, 21);
	printf("项目地址: %s", GITEE);
	for (i = 3; i < 23; i++)
	{
		Sleep(TIME);
		color(i % 15);
		toxy(100, i);
		printf("*");
	}
	toxy(L, 11);
	printf("2.查询系统模块");
	toxy(30, 11);
	for (i = 100; i >= 20; i--)
	{
		toxy(i, 23);
		if (i % 2 == 0)
		{
			color(i % 15);
			Sleep(TIME);
			printf("*");
		}
		else
		{
			printf(" ");
		}
	}
	toxy(L, 15);
	printf("3.管理系统模块");
	for (i = 23; i > 3; i--)
	{
		Sleep(TIME);
		color(i % 15);
		toxy(20, i);
		printf("*");
	}
	toxy(L, 19);
	printf("4.  退出系统  ");
	toxy(100, 24);
	color(7);
}
void managementSystem()
{
	int x = 32, y = 7; //横纵坐标
	char buf;		   //读取按键
	while (1)
	{
		HideCursor();
		system("cls");
		toxy(x, y);
		printf("->");
		show();
		buf = getch();
		switch (buf)
		{
		case 72:
			if (y > 7)
			{
				y -= 5;
			}
			else
			{
				y = 17;
			}
			break;
		case 80:
			if (y < 17)
			{
				y += 5;
			}
			else
			{
				y = 7;
			}
			break;
		case 77:
			if (x = 32)
			{
				x = 67;
			}
			break;
		case 75:
			if (x = 67)
			{
				x = 32;
			}
			break;
		case 13:
			MySelect(x, y);
			break;
		case 27:
			menu();
			break;
		}
	}
}
void over() //退出软件
{
	char t;
	toxy(48, 11);
	printf("-----------------------");
	toxy(48, 12);
	printf("|   您确定要退出吗？  |");
	toxy(48, 14);
	printf("| 1.确定     2.取消   |");
	toxy(48, 15);
	printf("-----------------------");
	while (1)
	{
		t = getch(); //输入t
		switch (t)
		{
		case '1':
			system("cls");
			color(6);
			toxy(48, 10);
			printf("正在安全退出....");
			Sleep(1000); //暂停1秒
			system("cls");
			color(8);
			toxy(48, 10);
			printf("已安全退出软件");
			toxy(48, 12);
			printf("谢谢使用！");
			toxy(48, 14);
			printf("by-by^_^");
			exit(0);
			break; //终止程序
		case '2':
			menu();
			break; //调用函数，进入菜单
		default:
			break;
		}
	}
}
void input()
{
	FILE *fp;
	if ((fp = fopen("employee.dat", "wb")) == NULL)
		exit(0);
	int i = 0, flag = 1;
	while (flag == 1)
	{
		system("cls");
		i++;
		toxy(50, 2);
		printf("第%d个职工", i);
		printf("\n");
		printf("请你输入工号:");
		scanf("%d", &em[i].num);
		printf("\n");
		printf("请你输入职位(董事长/总经理/副总经理/经理/副经理/秘书/技术员/领班/员工) :"); //输入职位
		scanf("%s", em[i].position);
		printf("\n");
		printf("请你输入姓名:");
		scanf("%s", em[i].name);
		printf("\n");
		printf("请你输入性别(男或女):");
		scanf("%s", em[i].sex);
		printf("\n");
		printf("请你输入文化程度（专家/博士/硕士/学士/其他）:"); //输入文化程度
		scanf("%s", em[i].cult);
		printf("\n");
		printf("请你输入工资:");
		scanf("%d", &em[i].salary);
		printf("\n");
		printf("请你输入身体情况（健康/良好/一般/差）:"); //身体情况
		scanf("%s", em[i].state);
		printf("\n");
		printf("是否继续输入?(1/0)");
		scanf("%d", &flag);
		//printf("输入的%c",flag);

		fwrite(&em[i], EMPLOYEE_LEN, 1, fp); //将信息写入文件
		if (flag == 0)
		{
			fclose(fp);
			printf("输入完毕,任意键返回\n");
			getch();
			return;
		}
	}
}

void show()
{

	toxy(20, 2);
	printf("*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*");
	toxy(20, 3);
	printf("*                                                                           *");
	toxy(20, 4);
	printf("#    --------------------欢迎进入309企业员工管理系统--------------------    #");
	int len, col;
	if (flag == 1)
	{
		for (len = 5; len < 20; len++)
		{
			toxy(20, len);
			color((len + 1) % 15);
			printf("*");
			Sleep(10);
			toxy(96, len);
			color((len) % 15);
			printf("*");
		}
		flag = 0;
	}
	else
	{
		for (len = 5; len < 20; len++)
		{
			toxy(20, len);
			color((len + 1) % 15);
			printf("*");
			//Sleep(10);
			color((len) % 15);
			toxy(96, len);
			printf("*");
		}
	}
	color(7);
	//左侧
	toxy(35, 7);
	printf("输入职工信息"); //32,7
	toxy(35, 12);
	printf("显示职工信息"); //32,12
	toxy(35, 17);
	printf("修改职工信息"); //32,17
	//右侧
	toxy(70, 7);
	printf("追加职工信息"); //67,7
	toxy(70, 12);
	printf("删除职工信息"); //67,12
	toxy(70, 17);
	printf("统计职工信息"); //67,17
	toxy(20, 20);
	printf("*                               ESC返回上级                                 *");
	toxy(20, 21);
	printf("*                                                                           *");
	toxy(20, 22);
	printf("*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*");
}
void MySelect(int x, int y)
{
	system("cls");
	if (x == 32 && y == 7)
	{
		//printf("输入职工信息");
		input();
	}
	else if (x == 32 && y == 12)
	{
		//printf("显示职工信息");
		display();
	}
	else if (x == 32 && y == 17)
	{
		//printf("修改职工信息");
		change();
	}
	else if (x == 67 && y == 7)
	{
		//printf("追加职工信息");
		add();
	}
	else if (x == 67 && y == 12)
	{
		//printf("删除职工信息");
		del();
	}
	else if (x == 67 && y == 17)
	{
		//printf("统计职工信息");
		count();
	}
	else if (x == 52 && y == 9)
	{
		inputcommunicate();
	}
	else if (x == 52 && y == 12)
	{
		deletecommunicate();
	}
	else if (x == 52 && y == 15)
	{
		showcommunicate();
	}
}
void color(short x)
{
	if (x == 0)
	{
		x = rand() % 14 + 1;
	}
	if (x >= 0 && x <= 15)
	{
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x);
	}
	else
	{
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x);
	}
}
void change()
{
	int i, j, snum, m;
	FILE *fp;
	if ((fp = fopen("employee.dat", "rb+")) == 0)
	{
		printf("打开失败");
		return;
	}
	while (!feof(fp))
	{
		if (fread(&em[m], EMPLOYEE_LEN, 1, fp) == 1)
		{
			m++;
		}
	}

	if (m == 0)
	{
		printf("无纪录");
		fclose(fp);
		return;
	}
	printf("请输入您要修改的员工工号:\n");
	scanf("%d", &snum);
	for (i = 0; i < m; i++)
		if (snum == em[i].num) /*检索记录中是否有要修改的信息*/
			break;
	if (i < m)
	{
		printf("请你输入工号:");
		scanf("%d", &em[i].num);
		printf("\n");
		printf("请你输入职位(董事长/总经理/副总经理/经理/副经理/秘书/技术员/领班/员工) :"); //输入职位
		scanf("%s", em[i].position);
		printf("\n");
		printf("请你输入姓名:");
		scanf("%s", em[i].name);
		printf("\n");
		printf("请你输入性别(男或女):");
		scanf("%s", em[i].sex);
		printf("\n");
		printf("请你输入文化程度（专家/博士/硕士/学士/其他）:"); //输入文化程度
		scanf("%s", em[i].cult);
		printf("\n");
		printf("请你输入工资:");
		scanf("%d", &em[i].salary);
		printf("\n");
		printf("请你输入身体情况（健康/良好/一般/差）:"); //身体情况
		scanf("%s", em[i].state);
		printf("\n");
	}
	else
	{
		printf("没有您要修改的员工信息!");
		return;
	}
	if ((fp = fopen("employee.dat", "w")) == NULL)
	{
		printf("系统出错,请与开发人员联系!\n");
		return;
	}
	for (j = 0; j < m; j++) /*将新修改的信息写入指定文件的磁盘文件中*/
		if (fwrite(&em[j], EMPLOYEE_LEN, 1, fp) != 1)
			printf("更新失败,请与开发人员联系!");
	fclose(fp);
}

void add()
{
	FILE *fp;
	if ((fp = fopen("employee.dat", "ab+")) == NULL)
		exit(0);
	int i = 0, flag = 1;
	while (flag == 1)
	{
		system("cls");
		i++;
		toxy(50, 2);
		printf("添加职工", i);
		printf("\n");
		printf("请你输入工号:");
		scanf("%d", &em[i].num);
		printf("\n");
		printf("请你输入职位(董事长/总经理/副总经理/经理/副经理/秘书/技术员/领班/员工) :"); //输入职位
		scanf("%s", em[i].position);
		printf("\n");
		printf("请你输入姓名:");
		scanf("%s", em[i].name);
		printf("\n");
		printf("请你输入性别(男或女):");
		scanf("%s", em[i].sex);
		printf("\n");
		printf("请你输入文化程度（专家/博士/硕士/学士/其他）:"); //输入文化程度
		scanf("%s", em[i].cult);
		printf("\n");
		printf("请你输入工资:");
		scanf("%d", &em[i].salary);
		printf("\n");
		printf("请你输入身体情况（健康/良好/一般/差）:"); //身体情况
		scanf("%s", em[i].state);
		printf("\n");
		printf("是否继续输入?(1/0)");
		scanf("%d", &flag);

		fwrite(&em[i], EMPLOYEE_LEN, 1, fp); //将信息写入文件
		if (flag == 0)
		{
			fclose(fp);
			printf("输入完毕,任意键返回\n");
			getch();
			return;
		}
	}
}
void del()
{
	FILE *fp;
	int snum, i, j, m = 0;
	char ch[2];
	if ((fp = fopen("employee.dat", "ab+")) == 0)
	{
		printf("打开文件错误，请联系开发人员");
		return;
	}
	while (!feof(fp))
		if (fread(&em[m], EMPLOYEE_LEN, 1, fp) == 1)
			m++;
	fclose(fp);
	if (m == 0)
	{
		printf("无纪录!\n");
		return;
	}
	printf("请输入您要删除的工号:");
	scanf("%d", &snum);
	for (i = 0; i < m; i++)
		if (snum == em[i].num)
			break;
	if (i == m)
	{
		printf("对不起,没有您要删除的员工信息!");
		getch();
		return;
	}
	printf("确认删除?(y/n)");
	scanf("%s", ch);
	if (strcmp(ch, "Y") == 0 || strcmp(ch, "y") == 0) /*判断是否要进行删除*/
	{
		for (j = i; j < m; j++)
			em[j] = em[j + 1]; /*将后一个记录移到前一个记录的位置*/
		m--;				   /*记录的总个数减一*/
		printf("删除成功!\n");
		getch();
	}
	if ((fp = fopen("employee.dat", "wb")) == NULL)
	{
		printf("系统出错,请与开发人员联系!\n");
		return;
	}
	for (j = 0; j < m; j++) /*将更改后的记录重新写入指定的磁盘文件中*/
		if (fwrite(&em[j], EMPLOYEE_LEN, 1, fp) != 1)
		{
			printf("更新失败,请与开发人员联系!\n");
		}
	fclose(fp);
}
void count()
{
	FILE *fp;
	int m;
	if ((fp = fopen("employee.dat", "r")) == NULL)
	{
		printf("系统错误,请联系开发容人员");
		return;
	}

	while (!feof(fp))
	{
		if (fread(&em[m], EMPLOYEE_LEN, 1, fp) == 1)
		{
			m++;
		}
	}
	toxy(45, 6);
	printf("-------档案管理统计-------");
	toxy(45, 7);
	printf("|                        |");
	toxy(45, 8);
	printf("|           本           |");
	toxy(45, 9);
	printf("|                        |");
	toxy(45, 10);
	printf("|           系           |");
	toxy(45, 11);
	printf("|                        |");
	toxy(45, 12);
	printf("|           统           |");
	toxy(45, 13);
	printf("|                        |");
	toxy(45, 14);
	printf("|           有           |");
	toxy(45, 15);
	printf("|                        |");
	toxy(45, 16);
	printf("|           %d            |", m);
	toxy(45, 17);
	printf("|                        |");
	toxy(45, 18);
	printf("|           条           |");
	toxy(45, 19);
	printf("|                        |");
	toxy(45, 20);
	printf("|           记           |");
	toxy(45, 21);
	printf("|                        |");
	toxy(45, 22);
	printf("|           录           |");
	toxy(45, 23);
	printf("--------------------------");
	fclose(fp);
}
void searchname() /*自定义函数实现按姓名查询员工信息*/
{
	int i, m = 0;
	char sname[20], ch[2];
	FILE *fp;
	if ((fp = fopen("employee.txt", "a+")) == NULL)
	{
		printf("系统出错，请与开发人员联系！\n");
		return;
	}
	while (!feof(fp))
		if (fread(&em[m], EMPLOYEE_LEN, 1, fp) == 1)
			m++;
	fclose(fp);
	if (m == 0)
	{
		printf("无记录！");
		getch();
		return;
	}
	printf("请输入您要查询的姓名：");
	scanf("%s", sname);
	for (i = 0; i < m; i++)
		if (strcmp(sname, em[i].name) == 0)
		{ /*查找输入的工号是否在记录中*/
			printf("查询成功,是否显示?(y/n)");
			scanf("%s", ch);
			if (strcmp(ch, "Y") == 0 || strcmp(ch, "y") == 0)
			{
				printf("工号 姓名 职位 性别 年龄 文化程度 工资 身体状况\t\n");
				//printf(FORMAT,DATA);/*将查出的结果按指定格式输出*/
				break;
			}
			else
				return;
		}
	if (i == m)
		printf("未找到该员工的信息！\n"); /*未找到要查找的信息*/
	getch();
}
//通讯录增加
void inputcommunicate()
{
	FILE *fp;
	if ((fp = fopen("communicate.dat", "ab+")) == NULL)
	{
		printf("文件打开失败，联系开发人员");
		return;
	}
	int num, index, flag;
	toxy(50, 2);
	printf("你要新增几位联系人信息？");
	toxy(56, 4);
	printf("请输入:___");
	toxy(64, 4);
	scanf("%d", &num);
	for (index = 0; index < num; index++)
	{
		system("cls");
		toxy(50, 2);
		printf("正在添加第%d位",index+1);
		toxy(45, 4);
		printf("请输入员工名字：");
		scanf("%s", &empc[index].name);
		toxy(45, 6);
		printf("请输入员工办公电话:");
		scanf("%s", &empc[index].officetel);
		toxy(45, 8);
		printf("请输入员工家庭电话：");
		scanf("%s", &empc[index].hometel);
		toxy(45, 10);
		printf("请输入员工手机号:");
		scanf("%s", &empc[index].handtel);
		toxy(45, 12);
		printf("请输入员工邮箱:");
		scanf("%s", &empc[index].address);
		fwrite(&empc[index], COMMUNICATION_LEN, 1, fp);
		//printf("demo%s",empc[index].address);
	}
	fclose(fp);
	printf("保存完成，按任意键返回上级");
	for (index = 3; index >= 0; index--)
	{
		Sleep(5);
		printf(".");
	}
	getch();
}

//通讯录删除
void deletecommunicate()
{
	FILE *fp;
	char name[5], ch[2];
	if ((fp = fopen("communicate.dat", "rb")) == NULL)
	{
		printf("文件打开失败，请联系开发人员");
		return;
	}
	int m = 0, index, j;
	while (!feof(fp))
	{
		if (fread(&empc[m], COMMUNICATION_LEN, 1, fp) == 1)
		{
			m++;
		}
	}
	fclose(fp);
	if (m == 0)
	{
		printf("无记录");
		return;
	}
	else
	{
		printf("输入你要删除的员工姓名：");
		scanf("%s", name);
		for (index = 0; index < m; index++)
		{
			if (strcmp(name, empc[index].name) == 0)
			{
				break;
			}
		}
		if (index == m)
		{
			printf("对不起,没有您要删除的员工信息!");
			getch();
			return;
		}
		printf("确认删除?(y/n)");
		scanf("%s", ch);
		if (strcmp(ch, "Y") == 0 || strcmp(ch, "y") == 0) /*判断是否要进行删除*/
		{
			for (j = index; j < m; j++)
				em[j] = em[j + 1]; /*将后一个记录移到前一个记录的位置*/
			m--;				   /*记录的总个数减一*/
			printf("删除成功!\n");
			getch();
		}
		if ((fp = fopen("communicate.dat", "wb")) == NULL)
		{
			printf("系统出错,请与开发人员联系!\n");
			return;
		}
		for (j = 0; j < m; j++) /*将更改后的记录重新写入指定的磁盘文件中*/
			if (fwrite(&em[j], COMMUNICATION_LEN, 1, fp) != 1)
			{
				printf("更新失败,请与开发人员联系!\n");
			}
		fclose(fp);
	}
}
void showcommunicate()
{
	FILE *fp;
	int i, x = 20, y = 4;
	int index, j;
	if ((fp = fopen("communicate.dat", "rb")) == NULL)
	{
		printf("文件打开失败，请联系开发人员");
		getch();
		return;
	}
	toxy(50, 2);
	printf("员工通讯录");
	toxy(x, y);
	printf("姓名");
	toxy(x += 15, y);
	printf("邮箱");
	toxy(x += 15, y);
	printf("手机号码");
	toxy(x += 15, y);
	printf("办公号码");
	toxy(x += 15, y);
	printf("家庭号码");
	for (index = 0; fread(&empc[index], COMMUNICATION_LEN, 1, fp) != 0; index++) //读出每行信息并输出
	{
		x = 20, y = 4;
		toxy(x, y + 2 + index);
		printf("%s", empc[index].name);
		toxy(x += 15, y + 2 + index);
		printf("%s", empc[index].address);
		toxy(x += 15, y + 2 + index);
		printf("%s", empc[index].handtel);
		toxy(x += 15, y + 2 + index);
		printf("%s", empc[index].officetel);
		toxy(x += 15, y + 2 + index);
		printf("%s", empc[index].hometel);
	}
	printf("\n按任意键继续！");
	getch();
	fclose(fp);
}
void loginshow()
{
	toxy(46, 6);
	printf("企业员工信息管理系统登录");
	toxy(46, 12);
	Sleep(10);
	printf("用户名:");
	toxy(46, 15);
	printf("密  码:");
	int index;
	color(4);
	toxy(38, 8);
	printf("X");
	toxy(77, 8);
	printf("X");
	for (index = 39; index < 77; index++)
	{
		if (index % 2 == 0)
		{
			color(index % 15);
			toxy(index, 8);
			Sleep(20);
			printf("*");
		}
	}
	color(4);
	toxy(38, 19);
	printf("X");
	toxy(77, 19);
	printf("X");
	for (index = 39; index < 77; index++)
	{
		if (index % 2 == 0)
		{
			color(index % 15);
			toxy(index, 19);
			Sleep(20);
			printf("*");
		}
	}
	for (index = 9; index <= 18; index++)
	{
		Sleep(50);
		toxy(38, index);
		color(index % 15);
		printf("%%");
		toxy(77, index);
		color(index % 15);
		printf("%%");
	}
}
void showcommunicatelist()
{
	toxy(50, 3);
	printf("X----------------X");
	toxy(54, 4);
	printf("员工通讯录");
	toxy(50, 5);
	printf("X----------------X");
	int x, y;
	toxy(48, 7);
	printf("X--------------------X");
	for (y = 8; y <= 18; y++)
	{
		/* code */
		//Sleep(30);
		toxy(48, y);
		printf("|");
		toxy(69, y);
		printf("|");
	}

	toxy(48, 18);
	printf("X--------------------X");
	toxy(56, 9);
	printf("添加人员");
	toxy(56, 12);
	printf("删除人员");
	toxy(56, 15);
	printf("通讯列表");
}
void communicateSystem()
{
	char buf;
	int x = 52, y = 9;
	do
	{

		system("cls");
		showcommunicatelist();
		toxy(x, y);
		printf("->");
		buf = getch();
		switch (buf)
		{
		case 72:
			if (y == 9)
			{
				y = 15;
			}
			else
			{
				y -= 3;
			}
			break;
		case 80:
			if (y == 15)
			{
				y = 9;
			}
			else
			{
				y += 3;
			}
			break;
		case 13:
			MySelect(x, y);
			//printf("%d,%d", x, y);
			break;
		case 27:
			menu();
			break;
		}
	} while (1);
}
void selctNum() //显示职工信息
{
	int num, m;
	system("cls");
	printf("输入你要查询的工号");
	scanf("%d", &num);
	FILE *fp;
	int i, x = 3, y = 4;
	if ((fp = fopen("employee.dat", "rb")) == NULL)
	{
		printf("文件打开失败，请联系开发人员");
		return;
	}
	toxy(50, 2);
	printf("员工列表如下");
	toxy(x, y);
	printf("工号");
	toxy(x += 15, y);
	printf("职位");
	toxy(x += 15, y);
	printf("姓名");
	toxy(x += 15, y);
	printf("姓别");
	toxy(x += 15, y);
	printf("文化程度");
	toxy(x += 15, y);
	printf("工资");
	toxy(x += 15, y);
	printf("身体情况");
	for (i = 0; fread(&em[i], EMPLOYEE_LEN, 1, fp) != 0; i++) //读出每行信息并输出
	{
		if (em[i].num == num)
		{
			x = 3, y = 4;
			toxy(x, y + 2 + i);
			printf("%d\t", em[i].num);
			toxy(x += 15, y + 2 + i);
			printf("%s\t", em[i].position);
			toxy(x += 15, y + 2 + i);
			printf("%s\t", em[i].name);
			toxy(x += 15, y + 2 + i);
			printf("%s\t", em[i].sex);
			toxy(x += 15, y + 2 + i);
			printf("%s\t", em[i].cult);
			toxy(x += 15, y + 2 + i);
			printf("%d\t", em[i].salary);
			toxy(x += 15, y + 2 + i);
			printf("%s\n", em[i].state);
			//printf("\n完毕按任意键返回");
		}
		m++;
	}
	if (m == 0)
	{
		toxy(50, 7);
		printf("无数据！");
	}
	//toxy(1,50);
	printf("\n按任意键返回");
	getch();
	fclose(fp);
	menu();
	return;
}
void display() //显示职工信息
{
	FILE *fp;
	int i, x = 3, y = 4;
	if ((fp = fopen("employee.dat", "rb")) == NULL)
		return;
	toxy(50, 2);
	printf("员工列表如下");
	toxy(x, y);
	printf("工号");
	toxy(x += 15, y);
	printf("职位");
	toxy(x += 15, y);
	printf("姓名");
	toxy(x += 15, y);
	printf("姓别");
	toxy(x += 15, y);
	printf("文化程度");
	toxy(x += 15, y);
	printf("工资");
	toxy(x += 15, y);
	printf("身体情况");
	for (i = 0; fread(&em[i], EMPLOYEE_LEN, 1, fp) != 0; i++) //读出每行信息并输出
	{

		x = 3, y = 4;
		toxy(x, y + 2 + i);
		printf("%d\t", em[i].num);
		toxy(x += 15, y + 2 + i);
		printf("%s\t", em[i].position);
		toxy(x += 15, y + 2 + i);
		printf("%s\t", em[i].name);
		toxy(x += 15, y + 2 + i);
		printf("%s\t", em[i].sex);
		toxy(x += 15, y + 2 + i);
		printf("%s\t", em[i].cult);
		toxy(x += 15, y + 2 + i);
		printf("%d\t", em[i].salary);
		toxy(x += 15, y + 2 + i);
		printf("%s\n", em[i].state);
		//printf("\n完毕按任意键返回");
	}
	//toxy(1,50);
	printf("\n按任意键返回");
	getch();
	fclose(fp);
	return;
}